<%
var CONST;
CONST.paginate = function(currentPage, totalPage, actionUrl, urlParas){

    if((totalPage <= 0) || (currentPage > totalPage)){
        return;
    }
    var startPage = currentPage - 4;
    
    if(startPage < 1){
        startPage = 1;
    }
    
    var endPage = currentPage + 4;
    
    if(endPage > totalPage){
        endPage = totalPage;
    }
    
    if(currentPage <= 8){
        startPage = 1;
    }
    if((totalPage - currentPage) < 8){
        endPage = totalPage;
    }
    
    var getUrlOfPage;
    if(urlParas){
        getUrlOfPage = function(page){
            return actionUrl + page + urlParas;
        };
    }else{
        getUrlOfPage = function(page){
            return actionUrl + page;
        };
    }

%>
    <div class="pagination">
    <% 
    if(currentPage == 1){
        %>
            <span class="disabled prev_page">上页</span>
        <%
    }else{
        %>
            <a href="${getUrlOfPage(currentPage - 1)}" class="prev_page">上页</a>
        <%
    }
    
    if(currentPage > 8){
        %>
            <a href="${getUrlOfPage(1)}">1</a>
            <a href="${getUrlOfPage(2)}">2</a>
            <span class="gap">…</span>
        <%
    }
    for(i : startPage..endPage){
        if(currentPage == i){
            %>
                <span class="current">${i}</span>
            <%
        }else{
            %>
                <a href="${getUrlOfPage(i)}">${i}</a>
            <%
        }
    }
    
    if((totalPage - currentPage) >= 8){
        %>
            <span class="gap">…</span>
            <a href="${getUrlOfPage(totalPage - 1)}">${totalPage - 1}</a>
            <a href="${getUrlOfPage(totalPage)}">${totalPage}</a>
        <%
    }
    
    if(currentPage == totalPage){
        %>
            <span class="disabled next_page">下页</span>
        <%
    }else{
        %>
            <a href="${getUrlOfPage(currentPage + 1)}" class="next_page" rel="next">下页</a>
        <%
    }
%>
    </div>
<%
}; // end paginate
%>